package top.zuli.package01.class15;

import org.junit.Test;

import java.io.UnsupportedEncodingException;

public class TestDemo5 {
    @Test
    public void StringConstructorTest() throws UnsupportedEncodingException {
        //创建一个空字符串
        String str = new String();
        System.out.println(str);
        //将byte数组按照指定编码转为字符串
        byte[] bb = {97,98,99};
        String str2 = new String(bb);
        System.out.println(str2);
        // 将byte数组按照指定编码转为字符串
        String str3 = new String(bb,"gbk");
        System.out.println(str3);
        // 将byte数组的部分内容按照平台默认编码转为字符串；需要设置开始下标，长度；
        String str4 = new String(bb,0,2);
        System.out.println(str4);
        //将byte数组的部分内容按照指定编码转为字符串；需要设置开始下标，长度；
        String str5 = new String(bb,0,2,"utf-8");
        System.out.println(str5);
        //将char数组转为字符串
        char[] cc = {'胖','叔'};
        String str6 = new String(cc);
        System.out.println(str6);
        //将char数组的部分内容转为字符串；需要指定开始下标，长度；
        String str7 = new String(cc,0,1);
        System.out.println(str7);
    }
}

/*
public class TestDemo5 {
    @Test
    public void StringConstructorTest() throws UnsupportedEncodingException {
        String str = new String();
        System.out.println(str);
        byte[] bb = {97,98,99};
        String str2 = new String(bb);
        System.out.println(str2);
        String str3 = new String(bb,"gbk");
        System.out.println(str3);
        String str4 = new String(bb,0,2);
        System.out.println(str4);
        String str5 = new String(bb,0,2,"utf-8");
        System.out.println(str5);
        char[] cc = {'胖','叔'};
        String str6 = new String(cc);
        System.out.println(str6);
        String str7 = new String(cc,0,1);
        System.out.println(str7);
    }
}

*/

/*
public class TestDemo5 {
    @Test
    public void StringConstructorTest() throws UnsupportedEncodingException {
        String str = new String();
        System.out.println(str);
        byte[] bb = {97,98,99};
        String str2 = new String(bb);
        System.out.println(str2);
        String str3 = new String(bb,"gbk");
        System.out.println(str3);
        String str4 = new String(bb,0,2);
        System.out.println(str4);
        String str5 = new String(bb,0,2,"utf-8");
        System.out.println(str5);
        char[] cc = {'胖','叔'};
        String str6 = new String(cc);
        System.out.println(str6);
        String str7 = new String(cc,0,1);
        System.out.println(str7);
    }
}

*/

/*
public class TestDemo5 {
    @Test
    public void StringConstructorTest() throws UnsupportedEncodingException {
        String str = new String();
        System.out.println(str);
        byte[] bb = {97,98,99};
        String str2 = new String(bb);
        System.out.println(str2);
        String str3 = new String(bb,"gbk");
        System.out.println(str3);
        String str4 = new String(bb,0,2);
        System.out.println(str4);
        String str5 = new String(bb,0,2,"utf-8");
        System.out.println(str5);
        char[] cc = {'胖','叔'};
        String str6 = new String(cc);
        System.out.println(str6);
        String str7 = new String(cc,0,1);
        System.out.println(str7);
    }
}

*/
